package com.qdlc.p2p.dal.dto;

import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import com.qdlc.p2p.common.constant.Global;
import com.qdlc.p2p.common.constant.SinaConstant;
import com.qdlc.p2p.common.util.DateUtil;

/**
 * 分账信息model (主要用于代付)
 *
 * @author liya
 * @version 1.1.0.0
 */
@Entity
@Table(name = Global.DB_PREFIX + "tpp_sina_split")
public class TppSinaSplit {

    public TppSinaSplit() {
    }

    public TppSinaSplit(String orderNo, String payIdentityId, String payIdentityType, String payAccountType,
                        String collIdentifyId, String collIdentityType, String collAccountType,
                        String amount, String remark) {
        this.orderNo = orderNo;
        this.payIdentityId = payIdentityId;
        this.payIdentityType = payIdentityType;
        this.payAccountType = payAccountType;
        this.collIdentifyId = collIdentifyId;
        this.collIdentityType = collIdentityType;
        this.collAccountType = collAccountType;
        this.amount = amount;
        this.remark = remark;
        this.addTime = DateUtil.getNow();
    }

    /** 主键 */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    /** 订单号 用于查询此笔分账属于哪个代付 */
    private String orderNo;

    /** 付款人标识 */
    private String payIdentityId;

    /** 付款人标识类型 */
    private String payIdentityType;

    /** 付款人账户类型 */
    private String payAccountType;

    /** 收款人标识 */
    private String collIdentifyId;

    /** 收款人标识类型 */
    private String collIdentityType;

    /** 收款人账户类型 */
    private String collAccountType;

    /** 金额 */
    private String amount;

    /** 备注 */
    private String remark;

    /** 添加时间 */
    private Date addTime;

    public static String getSplitList(List<TppSinaSplit> list, String memberEmail) {
        if (null == list || memberEmail == null) return "";
        StringBuffer sb = new StringBuffer(100);
        int i = 0;
        for (TppSinaSplit spilt : list) {
            if (i > 0) sb.append("|");
            sb.append(spilt.getPayIdentityId()).append("^");
            sb.append(spilt.getPayIdentityType()).append("^");
            // 商户 只能是基本型
            if (memberEmail.equals(spilt.getPayIdentityId())) {
                sb.append(SinaConstant.ACCOUNT_TYPE_BASIC).append("^");
            } else {
                sb.append(SinaConstant.ACCOUNT_TYPE_SAVING_POT).append("^");
            }
            sb.append(spilt.getCollIdentifyId()).append("^");
            sb.append(spilt.getCollIdentityType()).append("^");
            // 商户 只能是基本型
            if (memberEmail.equals(spilt.getCollIdentifyId())) {
                sb.append(SinaConstant.ACCOUNT_TYPE_BASIC).append("^");
            } else {
                sb.append(SinaConstant.ACCOUNT_TYPE_SAVING_POT).append("^");
            }
            sb.append(spilt.getAmount()).append("^");
            sb.append(spilt.getRemark());
            i++;
        }
        return sb.toString();
    }


    /**
     * 获取 付款人标识
     *
     * @return
     */
    public String getPayIdentityId() {
        return payIdentityId;
    }

    /**
     * 设置 付款人标识
     *
     * @param
     */
    public void setPayIdentityId(String payIdentityId) {
        this.payIdentityId = payIdentityId;
    }

    /**
     * 获取 付款人标识类型
     *
     * @return
     */
    public String getPayIdentityType() {
        return payIdentityType;
    }

    /**
     * 设置 付款人标识类型
     *
     * @param
     */
    public void setPayIdentityType(String payIdentityType) {
        this.payIdentityType = payIdentityType;
    }

    /**
     * 获取 付款人账户类型
     *
     * @return
     */
    public String getPayAccountType() {
        return payAccountType;
    }

    /**
     * 设置 付款人账户类型
     *
     * @param
     */
    public void setPayAccountType(String payAccountType) {
        this.payAccountType = payAccountType;
    }

    /**
     * 获取 收款人标识
     *
     * @return
     */
    public String getCollIdentifyId() {
        return collIdentifyId;
    }

    /**
     * 设置 收款人标识
     *
     * @param
     */
    public void setCollIdentifyId(String collIdentifyId) {
        this.collIdentifyId = collIdentifyId;
    }

    /**
     * 获取 收款人标识类型
     *
     * @return
     */
    public String getCollIdentityType() {
        return collIdentityType;
    }

    /**
     * 设置 收款人标识类型
     *
     * @param
     */
    public void setCollIdentityType(String collIdentityType) {
        this.collIdentityType = collIdentityType;
    }

    /**
     * 获取 收款人账户类型
     *
     * @return
     */
    public String getCollAccountType() {
        return collAccountType;
    }

    /**
     * 设置 收款人账户类型
     *
     * @param
     */
    public void setCollAccountType(String collAccountType) {
        this.collAccountType = collAccountType;
    }

    /**
     * 获取 金额
     *
     * @return
     */
    public String getAmount() {
        return amount;
    }

    /**
     * 设置 金额
     *
     * @param
     */
    public void setAmount(String amount) {
        this.amount = amount;
    }

    /**
     * 获取 备注
     *
     * @return
     */
    public String getRemark() {
        return remark;
    }

    /**
     * 设置 备注
     *
     * @param
     */
    public void setRemark(String remark) {
        this.remark = remark;
    }

    /**
     * 获取 Id 主键
     *
     * @return
     */
    public long getId() {
        return id;
    }

    /**
     * 设置 Id 主键
     *
     * @param
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * 获取 订单号
     *
     * @return
     */
    public String getOrderNo() {
        return orderNo;
    }

    /**
     * 设置 订单号
     *
     * @param
     */
    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    /**
     * 获取 添加时间
     *
     * @return
     */
    public Date getAddTime() {
        return addTime;
    }

    /**
     * 设置 添加时间
     *
     * @param
     */
    public void setAddTime(Date addTime) {
        this.addTime = addTime;
    }


}
